package com.bolt.admin.config;

import com.bolt.core.view.config.PageRepository;
import com.bolt.core.view.config.UIProperties;
import com.bolt.core.view.templates.FreemarkerTemplateEngine;
import com.bolt.support.spring.jpa.jpql.JPAQueryFactory;
import com.bolt.support.sqlconfig.builder.SqlTemplateFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;

import javax.persistence.EntityManager;
import java.io.IOException;

/**
 * Created by Administrator on 2019/1/11.
 */
@Configuration
public class BoltConfiguration {

    @Bean
    public SqlTemplateFactory createSqlTemplateBuilder() throws IOException {
        SqlTemplateFactory builder = new SqlTemplateFactory();
        builder.setSqlMapperLocations(
                new PathMatchingResourcePatternResolver().getResources("classpath:sqlconfig/sqlconfig*.xml"));
        return builder;
    }



    @Bean
    public JPAQueryFactory createJPAQueryFactory(EntityManager entityManager) {
        return new JPAQueryFactory(entityManager);
    }


    @Bean
    public OpenEntityManagerInViewFilter openEntityManagerInViewFilter() {
        return new OpenEntityManagerInViewFilter();
    }

}
